package com.ruoyi.project.dict.chengyu.service.impl;

import com.ruoyi.common.utils.JsonUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.dict.chengyu.domain.Chengyu;
import com.ruoyi.project.dict.chengyu.mapper.ChengyuMapper;
import com.ruoyi.project.dict.chengyu.service.IChengyuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 成语词典Service业务层处理
 *
 * @author shixiangwen
 * @date 2021-12-02
 */
@Service
@DataSource(DataSourceType.DICT)
public class ChengyuServiceImpl implements IChengyuService {

    @Autowired
    private ChengyuMapper chengyuMapper;

    /**
     * 查询成语词典
     *
     * @param id 成语词典ID
     * @return 成语词典
     */
    @Override
    public Chengyu selectChengyuById(Long id) {
        return chengyuMapper.selectChengyuById(id);
    }

    /**
     * 查询成语词典列表
     *
     * @param chengyu 成语词典
     * @return 成语词典
     */
    @Override
    public List<Chengyu> selectChengyuList(Chengyu chengyu) {
        return chengyuMapper.selectChengyuList(chengyu);
    }

    /**
     * 新增成语词典
     *
     * @param chengyu 成语词典
     * @return 结果
     */
    @Override
    public int insertChengyu(Chengyu chengyu) {
        return chengyuMapper.insertChengyu(chengyu);
    }

    /**
     * 修改成语词典
     *
     * @param chengyu 成语词典
     * @return 结果
     */
    @Override
    public int updateChengyu(Chengyu chengyu) {

        if (StringUtils.isNotEmpty(chengyu.getTags())) {
            chengyu.setTag(JsonUtil.toJson(chengyu.getTags()));
        }

        return chengyuMapper.updateChengyu(chengyu);
    }

    /**
     * 删除成语词典对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteChengyuByIds(String ids) {
        return chengyuMapper.deleteChengyuByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除成语词典信息
     *
     * @param id 成语词典ID
     * @return 结果
     */
    @Override
    public int deleteChengyuById(Long id) {
        return chengyuMapper.deleteChengyuById(id);
    }
}
